home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / uim / plugin.scm < prev    next >
Encoding:
Text File  |  2010-11-07  |  5.4 KB  |  171 lines

  1. ;;;
  2. ;;; $Id:$
  3. ;;;
  4. ;;; plugin.scm: Plugin for uim.
  5. ;;;
  6. ;;; Copyright (c) 2005-2009 uim Project http://code.google.com/p/uim/
  7. ;;;
  8. ;;; All rights reserved.
  9. ;;;
  10. ;;; Redistribution and use in source and binary forms, with or without
  11. ;;; modification, are permitted provided that the following conditions
  12. ;;; are met:
  13. ;;; 1. Redistributions of source code must retain the above copyright
  14. ;;;    notice, this list of conditions and the following disclaimer.
  15. ;;; 2. Redistributions in binary form must reproduce the above copyright
  16. ;;;    notice, this list of conditions and the following disclaimer in the
  17. ;;;    documentation and/or other materials provided with the distribution.
  18. ;;; 3. Neither the name of authors nor the names of its contributors
  19. ;;;    may be used to endorse or promote products derived from this software
  20. ;;;    without specific prior written permission.
  21. ;;;
  22. ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
  23. ;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. ;;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. ;;; ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
  26. ;;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28. ;;; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29. ;;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. ;;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31. ;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. ;;; SUCH DAMAGE.
  33. ;;;;
  34.  
  35. (require "util.scm")
  36.  
  37. (define uim-plugin-lib-load-path
  38.   (if (setugid?)
  39.       (list (string-append (sys-pkglibdir) "/plugin"))
  40.       (let ((home-dir (or (home-directory (user-name)) ""))
  41.         (ld-library-path (getenv "LD_LIBRARY_PATH")))
  42.     (filter string?
  43.         (append (list (getenv "LIBUIM_PLUGIN_LIB_DIR")
  44.                   (if home-dir
  45.                   (string-append home-dir "/.uim.d/plugin")
  46.                   '())
  47.                   (string-append (sys-pkglibdir) "/plugin"))
  48.             ;; XXX
  49.             (if ld-library-path
  50.                 (string-split ld-library-path ":")
  51.                 '()))))))
  52.  
  53. (define uim-plugin-scm-load-path
  54.   (if (setugid?)
  55.       (list (sys-pkgdatadir))
  56.       (let ((home-dir (or (home-directory (user-name)) "")))
  57.     (filter string?
  58.         (list (getenv "LIBUIM_SCM_FILES")
  59.               (if home-dir
  60.               (string-append home-dir "/.uim.d/plugin")
  61.               '())
  62.               (sys-pkgdatadir))))))
  63.  
  64. (define plugin-alist ())
  65. (define plugin-func-alist ())
  66.  
  67. (define-record 'plugin-entry
  68.   '((name      "")
  69.     ;;(desc      "")
  70.     ;;(author    "")
  71.     ;;(version   #f)
  72.     (library   #f)
  73.     (init-proc #f)
  74.     (quit-proc #f)))
  75.  
  76. (define plugin-list-append
  77.   (lambda (plugin-name library init quit)
  78.    (let ((entry (plugin-entry-new plugin-name library init quit)))
  79.      (set! plugin-alist
  80.        (append plugin-alist (list entry))))))
  81.  
  82. (define plugin-list-delete
  83.   (lambda (plugin-name)
  84.     (set! plugin-alist
  85.       (alist-delete plugin-name plugin-alist string=?))))
  86.  
  87. (define plugin-list-query
  88.   (lambda (plugin-name)
  89.     (assoc plugin-name plugin-alist)))
  90.  
  91. (define plugin-list-query-library
  92.   (lambda (plugin-name)
  93.     (let ((entry (plugin-list-query plugin-name)))
  94.       (and entry
  95.        (plugin-entry-library entry)))))
  96.  
  97. (define plugin-list-query-instance-init
  98.   (lambda (plugin-name)
  99.     (let ((entry (plugin-list-query plugin-name)))
  100.       (and entry
  101.        (plugin-entry-init-proc entry)))))
  102.  
  103. (define plugin-list-query-instance-quit
  104.   (lambda (plugin-name)
  105.     (let ((entry (plugin-list-query plugin-name)))
  106.       (and entry
  107.        (plugin-entry-quit-proc entry)))))
  108.  
  109.  
  110. ;; The name 'module' is adopted from a post from Hiroyuki. If you
  111. ;; feel bad about the meaning of 'module', post your opinion to
  112. ;; uim@fdo.
  113.  
  114. (define installed-im-module-list ())
  115. (define currently-loading-module-name #f)
  116.  
  117. ;;
  118. ;; TODO: write test for load-plugin
  119. ;; returns whether initialization is succeeded
  120. (define require-module
  121.   (lambda (module-name)
  122.     (set! currently-loading-module-name module-name)
  123.     (let ((succeeded (or (load-plugin module-name)
  124.              (try-require (string-append module-name ".scm")))))
  125.       (set! currently-loading-module-name #f)
  126.       succeeded)))
  127.  
  128. ;; TODO: write test
  129. (define load-module-conf
  130.   (lambda ()
  131.     (let* ((home-dir (or (home-directory (user-name)) ""))
  132.        (user-module-dir (if home-dir
  133.                 (string-append home-dir "/.uim.d/plugin/")
  134.                 #f))
  135.        (conf-file "installed-modules.scm")
  136.        (user-conf-file (if user-module-dir
  137.                    (string-append user-module-dir conf-file)
  138.                    #f)))
  139.       (try-load conf-file)
  140.       (if (or
  141.        (setugid?)
  142.        (not user-conf-file))
  143.       #f
  144.       (if (not (getenv "LIBUIM_VANILLA"))
  145.           (let ((orig-module-list installed-im-module-list)
  146.             (orig-enabled-list enabled-im-list))
  147.         (if (try-load user-conf-file)
  148.             (begin
  149.               (set! installed-im-module-list
  150.                 (append orig-module-list installed-im-module-list))
  151.               (set! enabled-im-list
  152.                 (append orig-enabled-list enabled-im-list))))))))))
  153.  
  154.  
  155. ;; TODO: write test
  156. (define load-enabled-modules
  157.   (lambda ()
  158.     (let* ((home-dir (or (home-directory (user-name)) ""))
  159.        (user-module-dir (if home-dir
  160.                 (string-append home-dir "/.uim.d/plugin/")
  161.                 #f))
  162.        (file "loader.scm")
  163.        (user-file (if user-module-dir
  164.               (string-append user-module-dir file)
  165.               #f)))
  166.       (and (try-load file)
  167.        (or (and (not (setugid?))
  168.             user-file
  169.             (try-load user-file))
  170.            #t)))))
  171.